var DocData={
    userInfo:{
        userId:baseFn.getQueryString('userId',true)
    },
    payWay:3,
    newRenderCountIn:function(data){
        var _opts = $.extend({},{
            userId: '',
            userName:'',
            countIn:0
        },data || {})
        this.payWay=3    
        //提示窗
        $('.js_userName').text(_opts.userName)
        $('.js_countmn').val(Number(_opts.countIn))
    },
    bookingTime:{
        timepicker: true,    //开启时间选项
        yearStart: 2000,//设置最小年份
        minDate: 0,
        yearEnd: 2050,        //设置最大年份
        maxDate:false,
        allowTimes: ['09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00','21:00','22:00','23:00'],
        onSelectDate:function(){},
        onSelectTime:function(){
            var _val = $('.js_bookingTime').val()
            if(baseFn.notNull(_val)){
                var _datas={
                    subclinicId:$('.js_subclinicId').val(),
                    bookingTime:_val+':00'
                }
                selectDoctor(_datas)
            }
        }
    },
    sendBooking:false
}
$('.bespeak_change_look tbody').css('max-height',windowOffsetData.mainWraperHeight-110)
if(baseFn.notNull(DocData.userInfo.userId)){
    baseFn.$get({
        url:'user/selectUserInfo',
        data:{
            userId:DocData.userInfo.userId
        },
        calFn:function(res){
            DocData.userInfo = res.userInfo;
            $('.js_searchbox_wrap').addClass('hidden')
            $('.js_searchtxt_wrap').removeClass('hidden')
            if(baseFn.notNull(DocData.userInfo)){
                $('.js_searchtxt_wrap').find('span').text('您选择的会员是'+DocData.userInfo.userName)
            }
            $('.js_searchtxt_wrap').find('a').text('重新选择')
            DocData.newRenderCountIn({
                userId:DocData.userInfo.userId,
                userName:DocData.userInfo.userName,
                countIn:0
            })
        }
    })
}
/*新增预约*/
// 搜索用户
// 搜索框
$('#searchbox').select2({
    placeholder: '请输入会员手机号或姓名',
    language:{
        noResults:function(){return '<span class="font_blue">没有查询到该会员！</span>'},
        searching:function(){return '查询中。。。'}
    },
    allowClear: true,
    ajax: {
        url: baseUrl.base+"user/selectUserList",
        type: "get",
        dataType: 'json',
        data: function (params) {
            return {
                userPhone: params.term
            }
        },
        processResults: function (data) {
            var dataResult =[];
            var dataItem = data.results.rows;
            for(var i=0;i<dataItem.length;i++){
                var resultObj = {id:'',text:''};
                dataItem[i].text = dataItem[i].userName + '-' +baseFn.getHidePhoneStr(dataItem[i].userPhone);
                dataItem[i].id = dataItem[i].userId;
                dataResult.push(dataItem[i]);
            }
            return {
                results:dataResult,
            }
        }
    },
    escapeMarkup: function (markup) {return markup; }, // 自定义格式化防止xss注入
    minimumInputLength: function(e){
        var _val = e.term;
        if(/^[\u4e00-\u9fa5]{1,5}$/.test(_val)){
            return 1
        }else{
            return 3
        }
    }//最少输入多少个字符后开始查询
});
// 搜索框选中
$("#searchbox").on("select2:select",function(e){
    $('.js_searchbox_wrap').addClass('hidden')
    $('.js_searchtxt_wrap').removeClass('hidden')
    DocData.userInfo = e.params.data;
    if(baseFn.notNull(DocData.userInfo)){
        $('.js_searchtxt_wrap').find('span').text('您选择的会员是'+DocData.userInfo.userName)
    }
    $('.js_searchtxt_wrap').find('a').text('重新选择')
    DocData.newRenderCountIn({
        userId:e.params.data.userId,
        userName:e.params.data.userName,
        countIn:0
    })
})
$('.js_searchtxt_wrap a.research').on('click',function(){
    $('.js_bookingInfo_txt').addClass('hidden')
    $('.js_searchtxt_wrap').addClass('hidden')
    $('.js_searchbox_wrap').removeClass('hidden')
    $('#searchbox').val(null).trigger('change')
    DocData.newRenderCountIn({
        userId:'',
        userName:'待搜索',
        countIn:0
    })
})
// 点击(自定义)充值
$('.edit_ok').click(function () {
    var _upDatas = {
        userId: DocData.userInfo.userId,
        rechargeAccount:Number($('.js_countmn').val()),
        rechargeDesc:$('.js_desc').val(),
        payWay:DocData.payWay
    }
    var _txt=''
    //验证
    if (!baseFn.notNull(_upDatas.userId)) {
        _txt = '请选择会员'
    }
    if (!baseFn.notNull(_upDatas.rechargeAccount) || _upDatas.rechargeAccount == 0) {
        _txt = '请输入不为0的数字'
    }
    if (_upDatas.rechargeAccount <= 0) {
        _txt = '请输入大于0的数字'
    }
    if(_txt != ''){
        baseFn.infoDialog(_txt)
        return false
    }
    if(DocData.sendBooking){
        baseFn.infoDialog('预约正在提交中，不要重复操作');
        return false
    }
    DocData.sendBooking=true
    baseFn.dialog({
        content:"您确定为该会员进行充值么？",
        ok:function(){
            $.ajax({
                type: "POST",
                url: baseUrl.base + "user/customRecharge",
                data:_upDatas,
                success: function (res) {
                    if (res.code == 0) {
                        baseFn.infoDialog('充值成功！')
                        window.location.reload()
                    }else{
                        baseFn.infoDialog(res.msg)
                    }
                },
                complete:function(){
                    DocData.sendBooking=false
                }
            });
        }
    })
});

// 点击(对账扣款)提交
$('.deduction_submit').click(function () {
    var _upDatas = {
        userId: DocData.userInfo.userId,
        rechargeAccount: Number($('.js_countmn').val()),
        rechargeDesc: $('.js_desc').val(),
        payWay:DocData.payWay,
        deduction:1
    }
    var _txt=''
    //验证
    if (!baseFn.notNull(_upDatas.userId)) {
        _txt = '请选择会员'
    }
    if (!baseFn.notNull(_upDatas.rechargeAccount) || _upDatas.rechargeAccount == 0) {
        _txt = '请输入不为0的数字'
    }
    if (_upDatas.rechargeAccount <= 0) {
        _txt = '请输入大于0的数字'
    }
    _upDatas.rechargeAccount = Math.abs(_upDatas.rechargeAccount) * -1;


    if(_txt != ''){
        baseFn.infoDialog(_txt)
        return false
    }
    if(DocData.sendBooking){
        baseFn.infoDialog('预约正在提交中，不要重复操作');
        return false
    }
    DocData.sendBooking=true
    baseFn.dialog({
        content:"您确定为该会员进行对账(扣款)么？",
        ok:function(){
            $.ajax({
                type: "POST",
                url: baseUrl.base + "user/customRecharge",
                data:_upDatas,
                success: function (res) {
                    if (res.code == 0) {
                        baseFn.infoDialog('对账(扣款)成功！')
                        window.location.reload()
                    }else{
                        baseFn.infoDialog(res.msg)
                    }
                },
                complete:function(){
                    DocData.sendBooking=false
                }
            });
        }
    })
});

$('.edit_cancel').click(function(){
    history.go(-1)
})
$('.payelm').on('click',function(){
    var _parent = $(this).parents('.zccardelm')
    _parent.find('.payelm').removeClass('active')
    $(this).addClass('active')
    DocData.payWay=$(this).attr('rel')//支付方式
})
/*新增预约*/
/*基础设置*/

